package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.applySupplierBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getInviteDistributorPicBean;
import com.ymatou.iapi.godmch.parameter.getLoginUserRoleBean;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.applySupplierCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.getInviteDistributorPicCall;
import com.ymatou.iapi.godmch.service.getLoginUserRoleCall;
import com.ymatou.iapi.godmch.service.registerByCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*获取独立商户当前登录用户的角色
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getLoginUserRoleParam{
	private static getLoginUserRoleBean bean;
	private static getLoginUserRoleCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取独立商户当前登录用户的角色");
	}

	@Before
	public void caseUp() {
		bean=new getLoginUserRoleBean();
		call=new getLoginUserRoleCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getLoginUserRole_001() {
		Logger.start(true,"正例-获取独立商户当前登录用户的角色-loginUserId独立商户");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setLoginUserId(createIndepMchCall.getmchId());
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			//1：独立商户自身 2：供货商 3：代理商
			Logger.verifyEquals(1, call.getRole(), "验证Role");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getLoginUserRole_002() {
		Logger.start(true,"正例-获取独立商户当前登录用户的角色-loginUserId独立商户供货商");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请供货商
            applySupplierBean applySupplierBean=GodmchManageCallService.initApplySupplier(createIndepMchCall.getmchId());
            applySupplierCall applySupplierCall=GodmchManageCallService.applySupplierCall(applySupplierBean);
            //通过
            GodmchManageCallService.approveSupplier(createIndepMchCall.getmchId(), applySupplierCall.getSupplierId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setLoginUserId( applySupplierCall.getSupplierId());
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			//1：独立商户自身 2：供货商 3：代理商
			Logger.verifyEquals(2, call.getRole(), "验证Role");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getLoginUserRole_003() {
		Logger.start(true,"正例-获取独立商户当前登录用户的角色-loginUserId独立商户代理商");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //申请独立商户的代理
            applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(createIndepMchCall.getmchId());
            
            bean.setMchId(createIndepMchCall.getmchId());
            bean.setLoginUserId( applyAgentCall.getAgentId());
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			//1：独立商户自身 2：供货商 3：代理商
			Logger.verifyEquals(3, call.getRole(), "验证Role");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_getLoginUserRole_004() {
		Logger.start(true,"正例-获取独立商户当前登录用户的角色-loginUserId是平台渠道-返回错误(这个场景本来就是只有独立商户的app才会调用,如果两个值一样，肯定是独立商户自己)");
		try {
			//渠道
			UserCreateBean usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId_channl=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			
			bean.setMchId(userId_channl);
            bean.setLoginUserId(userId_channl);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			//1：独立商户自身 2：供货商 3：代理商
			Logger.verifyEquals(1, call.getRole(), "验证Role");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getLoginUserRole_005() {
		Logger.start(true,"正例-获取独立商户当前登录用户的角色-loginUserId是平台渠道-返回错误");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
			
			UserCreateBean  usercreateBean1=DGUserCallService.initUsercreateBean();
			int userId=DGUserCallService.UserCreateCall(usercreateBean1);
			
			createmchBean createmchbean=GodmchManageCallService.InitcreatemchBeanForChannel(createIndepMchCall.getmchId());
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			
			bean.setMchId(createIndepMchCall.getmchId());
            bean.setLoginUserId(userId);
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			//1：独立商户自身 2：供货商 3：代理商
			Logger.verifyEquals(0, call.getRole(), "验证Role");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getLoginUserRole_006() {
		Logger.start(true,"正例-获取独立商户当前登录用户的角色-loginUserId是分销员");
		try {
			//创建独立商户1
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            //商户分享二维码图片
            getInviteDistributorPicBean getInviteDistributorPicBean=GodmchManageCallService.initGetInviteDistributorPicBean();
            getInviteDistributorPicCall getInviteDistributorPicCall=GodmchManageCallService.getInviteDistributorPicBeanCall(getInviteDistributorPicBean);
    		//分销员邀请码注册
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(createIndepMchCall.getmchId(), getInviteDistributorPicCall.getResult().get("inviteCode").getAsString());
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            
            bean.setMchId(registerByCodeCall.getRegMchId());
            bean.setLoginUserId(registerByCodeCall.getRegMchId());
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("请求成功"), "验证Message");
			//1：独立商户自身 2：供货商 3：代理商 4：分销员
			Logger.verifyEquals(4, call.getRole(), "验证Role");
			Logger.verifyEquals(getInviteDistributorPicBean.getDistributorId(), call.getShopId(), "验证ShopId");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}